package com.vtech.ont.tdb.config;

import com.google.common.base.Strings;
import com.vtech.ont.base.config.JenaConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * TDB 连接配置(结合Spring)
 * TODO 设计是否合理？
 *
 * @author houzhiwei
 * @date 2017/7/14 21:51
 * @since 1.0
 */
/*@Configuration
@PropertySource(value = "classpath:/config/jena.properties")*/
public class TdbConfiguration extends JenaConfiguration {

    // jena.tdb.location 与 jena.tdb.assembler-file 只需配置其中一个
    @Bean(name = "tdbDataSource")
    public TdbDataSource tdbSource() {
        TdbDataSource source = new TdbDataSource();
        source.setTdbLocation(env.getProperty(TDB_LOCATION));
        source.setAssemblerFileLocation(env.getProperty(TDB_ASSEMBLER_FILE));

        // 基于 JDBC 访问 TDB 时的配置
        source.setTdbJdbcUrl(env.getProperty(JDBC_TDB_URL));
        // 当配置 must-exist 时，url 也必须配置
        String must = env.getProperty(JDBC_TDB_MUST_EXIST,"false");
        if (Strings.isNullOrEmpty(must))
            source.setTdbJdbcMustExist(Boolean.getBoolean(must));
        return source;
    }
}
